﻿using System;
using System.Windows.Forms;
using ExtendLib;
using ExtendLib.Helper;
using InterfaceLib;
using Ivony.Fluent;

namespace SmsBomb
{
    public partial class mainTest : Form
    {
        public int KeyId { get; set; }
        public mainTest()
        {
            InitializeComponent();
        }
        /// <summary>
        /// 测试
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void btnTest_Click(object sender, EventArgs e)
        {
            string url = this.txtUrl.Text, postData = this.txtPostData.Text;
            var urlHost = new Uri(url);
            MsgModel model = new MsgModel();
            // model.BaseUrl = "http://account.youku.com";
            //model.PostUrl = "/passport/sendMobileCode.json?bizType=register&sendCodeType=mobileCode&formtoken=7B7EDDAFEFD26B95B0B4C61B98C04531&buid=youku&pid=20160317PLF000211&mobileNo={0}&region=CN&jsToken=HV01PAAZ0bba5913b7279f3759803bac01196ae6&jsonpCallback=__jp1";
            model.BaseUrl = urlHost.Scheme + "://" + urlHost.Host;
            model.PostUrl = url.Replace(model.BaseUrl, "");
            model.RequestType = postData.IsNullOrEmpty() ? ERequestType.Get : ERequestType.Post;
            model.UseAgent = this.txtUseAgent.Text;
            model.SuccessFlag = this.txtFlag.Text;
            model.PostData = postData;
            model.Wait =int.Parse(this.txtWait.Text);
            var send = new ExtendOne(model,this.txtPhone.Text,this.txtIp.Text,this.txtPort.Text);
            string errMsg;
            if (send.Verify(out errMsg))
            {
                errMsg = "通过" + errMsg;
            }
            else
            {
                errMsg = "失败" + errMsg;
            }
            this.txtResult.Text =errMsg;

        }
        /// <summary>
        /// 窗口加载
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void mainTest_Load(object sender, EventArgs e)
        {
            var model = DbHelperByDapper.GetModel<MsgModel>(KeyId);
            this.txtUrl.Text = model.BaseUrl + model.PostUrl;
            this.txtPostData.Text = model.PostData;
            this.txtFlag.Text = model.SuccessFlag;
            this.txtUseAgent.Text = model.UseAgent;
            this.txtWait.Text = model.Wait.ToString();
        }
    }
}
